<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        width: 300px;
        height: 300px;
        border: solid;
        position: relative;
      }

      #ball {
        width: 100px;
        height: 100px;
        border: solid;
        background-color: yellow;
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div id="ball"></div>
    </div>
    <script>
      const box = document.getElementById("box");
      const ball = document.getElementById("ball");

      ball.style.left = (box.offsetWidth - ball.offsetWidth) / 2 + "px";
      ball.style.top = (box.offsetHeight - ball.offsetHeight) / 2 + "px";
    </script>
  </body>
</html>
